package com.yc.boottxx;

import com.yc.boottxx.controller.LoginInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;

@SpringBootApplication
@MapperScan("com.yc.boottxx.mapper")
public class BootTxxApplication implements WebMvcConfigurer {

    public static void main(String[] args) {
        SpringApplication.run(BootTxxApplication.class, args);
    }

    @Value("${myconfig.static-path}")
    String staticPath;
    @Value("${myconfig.upload-path}")
    String uploadPath;
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/**")
                .addResourceLocations(staticPath)
                .addResourceLocations("file:/root/yc136/boot-txx/login-starter" +
                        "/login-starter/src/main/resources/static/");
//                .addResourceLocations("file:E:\\作业\\idea工程\\yc136-git\\boot-txx" +
//                        "\\login-starter\\login-starter\\src\\main\\resources\\static/");
//        registry.addResourceHandler("/lg/**")
//                .addResourceLocations("file:E:\\作业\\idea工程\\yc136-git\\boot-txx" +
//                        "\\login-starter\\login-starter\\src\\main\\resources\\static\\lg/");

        registry.addResourceHandler("/lg/**")
                .addResourceLocations("file:/root/yc136/boot-txx/login-starter" +
                        "/login-starter/src/main/resources/static/lg/");
//        registry.addResourceHandler("/lg/**")
//                .addResourceLocations("file:D:\\Git-work\\git_URL\\boot-txx\\login-starter" +
//                        "\\login-starter\\src\\main\\resources\\static\\lg/");
//        registry.addResourceHandler("/upload/**")
//                .addResourceLocations(uploadPath);
    }
//    @Override
//    public void addInterceptors(InterceptorRegistry registry) {
//        registry.addInterceptor(new LoginInterceptor())
//                .addPathPatterns("/addCar.html","/Userinfo.html","password.html",
//                        // 提交订单的 ajax 请求
//                        "/txx/lease/commit");
//    }

    @Bean
    public ServerEndpointExporter serverEndpointExporter(){
        return new ServerEndpointExporter();
    }
}
